<script>
var imagesSuffix=["png","gif","jpg","jpeg","bmp"];
var videosSuffix=["ogg","webm","mpeg","mpg","mov","rm","ram","avi","wmv","mp4"];
function checkFileType(){
<#if onlyImage?has_content>
    <#assign fileTypes='image'/>
    var filenames=$('input[name=file]',$.pdialog.getCurrent()).val().toLowerCase().split('.');
    if(-1 != $.inArray(filenames[filenames.length-1], imagesSuffix)){
        return true;
    }
    alertMsg.error('<@t.page 'upload.image_warn'/>');
    return false;
<#elseif onlyVideo?has_content>
    <#assign fileTypes='video'/>
    var filenames=$('input[name=file]',$.pdialog.getCurrent()).val().toLowerCase().split('.');
    if(-1 != $.inArray(filenames[filenames.length-1], videosSuffix)){
        return true;
    }
    alertMsg.error('<@t.page 'upload.video_warn'/>');
    return false;
<#else>
    return true;
</#if>
}
function selectFile(path){
<#if onlyImage?has_content>
    var filenames=path.toLowerCase().split('.');
    if(-1 != $.inArray(filenames[filenames.length-1], imagesSuffix)){
        return true;
    }
    alertMsg.error('<@t.page 'upload.image_warn'/>');
    return false;
<#elseif onlyVideo?has_content>
    var filenames=path.toLowerCase().split('.');
    if(-1 != $.inArray(filenames[filenames.length-1], videosSuffix)){
        return true;
    }
    alertMsg.error('<@t.page 'upload.video_warn'/>');
    return false;
<#else>
    return true;
</#if>
}
</script>
<form action="file/doUpload.do" method="post" enctype="multipart/form-data" class="pageForm required-validate" onsubmit="return iframeCallback(this, $.bringBack)">
    <input type="hidden" name="_csrf" value="<@_csrfToken admin=true/>"/>
    <div class="pageFormContent" layoutH="50">
        <div id="preview" style="position:relative;"><div style="position:absolute;top:0px;right:0;z-index:1000;"><img style="max-height:200px;max-width:300px;"/></div></div>
        <dl class="nowrap">
            <dt><@t.page 'file'/>:</dt>
            <dd>
                <input type="hidden" name="field" value="${field!'fileName'}"/>
                <input type="hidden" name="originalField" value="${originalField!}"/>
                <input type="file" name="file" class="required" size="30"<#if onlyImage?has_content> accept="image/*"<#elseif onlyVideo?has_content> accept="video/*"</#if>/>
            </dd>
        </dl>
        <ul class="tree" style="height:200px">
        <#if admin?has_content>
    <@_logUploadList userId=admin.id fileTypes=fileTypes pageIndex=1 count=5>
        <#list page.list as a>
            <li><a href="javascript:;" data-src="${a.filePath!}" onclick="if(selectFile('${a.filePath!}')){$.bringBack({'${field!'fileName'}':'${a.filePath!}','fileType':'${a.fileType!}','fileSize':'${a.fileSize!}','${originalField!'originalName'}':'${a.originalName!}'});}return false;">${(a.originalName?has_content)?then(a.originalName,a.filePath!)}</a></li>
        </#list>
    </@_logUploadList>
        </ul>
        <script>
            $('ul li a',$.pdialog.getCurrent()).hover(function(){
                var filenames=$(this).text().toLowerCase().split('.');
                if(-1 != $.inArray(filenames[filenames.length-1], imagesSuffix)){
                    if(-1<$(this).text().indexOf("://")||0==$(this).text().indexOf("//")){
                        $('#preview',$.pdialog.getCurrent()).show().find('img').attr('src',$(this).data('src'));
                    }else{
                        $('#preview',$.pdialog.getCurrent()).show().find('img').attr('src','${site.sitePath}'+$(this).data('src'));
                    }
                }
            },function(){
                $('#preview',$.pdialog.getCurrent()).hide();
            });
        </script>
        </#if>
    </div>
    <div class="formBar">
        <ul>
            <li><button type="submit" class="buttonActive" onclick="return checkFileType();"><@t.page 'upload'/></button></li>
            <li><button type="button" class="button" onclick="$.bringBack({'${field}':''});return false;"><@t.page 'button.clear_select'/></button></li>
            <li><button type="button" class="button close"><@t.page 'button.close'/></button></li>
        </ul>
    </div>
</form>